//
//  ST_PairsMyCenterHeaderView.swift
//  btvideo
//
//  Created by mac on 2020/1/10.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_PairsMyCenterHeaderView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(pairsHeader)
        
        
        self.addSubview(bottom_root_view)
        bottom_root_view.addSubview(heart_image_view)
        bottom_root_view.addSubview(like_count_label)
        
        bottom_root_view.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-21)
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
        }
        heart_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(18)
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        like_count_label.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.left.equalTo(heart_image_view.snp.right).offset(6)
            make.centerY.equalToSuperview()
        }
        
        
        
        
        self.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-27)
            make.left.equalToSuperview().offset(27)
            make.bottom.equalTo(bottom_root_view.snp.top).offset(-13)
        }
        
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-27)
            make.left.equalToSuperview().offset(27)
            make.bottom.equalTo(content_label.snp.top).offset(-11)
        }
        
        self.addSubview(video_progress_view)
        video_progress_view.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.bottom.equalTo(titleLabel.snp.top).offset(-31)
            make.height.equalTo(ST_PlayVideoProgressView.height)
        }
        
        pairsHeader.progress_closure = { progress,idx in
            self.video_progress_view.setProgress(percentValue: progress, currentIdx: idx)
        }
        
        
        /*
        let nextVideoWidth = 150
        self.addSubview(next_video_btn)
        self.addSubview(previous_video_btn)
        next_video_btn.snp.makeConstraints { (make) in
            make.right.top.equalToSuperview()
            make.bottom.equalTo(bottom_root_view.snp.top).offset(-80)
            make.width.equalTo(nextVideoWidth)
        }
        
        previous_video_btn.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview()
            make.bottom.equalTo(bottom_root_view.snp.top).offset(-80)
            make.width.equalTo(nextVideoWidth)
        }
         */
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    var phDelegate:ST_PairsShareParticularViewDelegate?{
        didSet{
            pairsHeader.phDelegate = self.phDelegate
        }
    }
    
    lazy var pairsHeader:ST_PairsShareParticularView = {
        let control = ST_PairsShareParticularView()
        control.frame = CGRect.init(x: 0, y: 0, width: ScreenWidth, height: 100)
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.semibold)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = "  "
        control.textColor = Color.init(hexString: "#61666F")
        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var like_count_label:UILabel = {
        let control = UILabel.init()
        control.text = "  "
        control.textColor = Color.init(hexString: "#333333")
        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var heart_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("个人中心_icon_收的喜欢")
        return control
    }()
    
    
    fileprivate lazy var bottom_root_view:UIView = {
        let control = UIView()
        control.backgroundColor = Color.clear
        return control
    }()
    

//    fileprivate lazy var next_video_btn:UIButton = {
//
//        let control = UIButton.init(type: UIButton.ButtonType.custom)
//
////        control.backgroundColor = Color.init(white: 0, alpha: 0.2)
//
//        control.addTarget(self, action: #selector(play_next_video), for: UIControl.Event.touchUpInside)
//
//        return control
//    }()
//
//
//     fileprivate lazy var previous_video_btn:UIButton = {
//
//        let control = UIButton.init(type: UIButton.ButtonType.custom)
//
////        control.backgroundColor = Color.init(white: 0, alpha: 0.2)
//
//        control.addTarget(self, action: #selector(play_previous_video), for: UIControl.Event.touchUpInside)
//
//        return control
//    }()

//    MARK: - 进度条
    fileprivate lazy var video_progress_view:ST_PlayVideoProgressView = {
        let control = ST_PlayVideoProgressView()
        return control
    }()
    
//    MARK: - Bind Model
    var mdoel:ST_PairsMyCenterHeaderViewModel?
    
    func bind_model(_ model:ST_PairsMyCenterHeaderViewModel){
        
        self.mdoel = model
        
        titleLabel.text = model.nickname + "  " +  model.age.string + "岁"
        
        
        if let atrr = model.signAttri{
            content_label.attributedText = atrr
        }
        like_count_label.text = model.liked_num.string + "人喜欢了你"
        
        pairsHeader.setUp(data_array: model.particularArray)

        video_progress_view.create_items(count: model.particularArray.count)
        
        video_progress_view.isHidden = model.particularArray.count < 2
    }
    
    
    
}

/**
extension ST_PairsMyCenterHeaderView{
   
    @objc fileprivate func play_next_video(){
        
        self.pairsHeader.scrollToNext()
    }
    
    @objc fileprivate func play_previous_video(){
        self.pairsHeader.scrollToPrevious()
    }
}
*/

class ST_PairsMyCenterHeaderViewModel {
    
    var accid = ""
    var nickname = ""
    var age = 18
    var sign = ""
    var liked_num = 0
    var nobilityImg:String?
    var guardTime = 0
    var guardContent = ""
    
    var vipExpire = 0
    
    var sex = ST_SEX.unkown
//    别人主页
    var online_state = ""
    var address = ""
    var distance = ""
    
    /**真人认证状态*/
    var face_audit_state = 1
    /**
     是否展示现在活跃
     */
    var is_show_active = false
    
    /// 语音签名
    var voiceSignUrl:URL?
    var voiceSignDuration = 0
    /**
     关注
     */
    var is_attention = false
    
    /**
     是好友
     */
    var is_friends = false
    
    
    var particularArray = [ST_PairsShareParticularModel]()
    
    
    var signAttri:NSAttributedString?
    
    var headerExtensionHeight = 50.cgFloat
    
    var guideModel:PairsGuardModel?
    
    var isMyGuard = false
    
    func setUpViewDataSet(){
        
        var text = sign
        
        if text.isEmpty{
            text = "星光月夜皆归你，我也归你"
        }
        
        let attrString = NSMutableAttributedString(string: text)
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.19, alpha: 1)]
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        self.signAttri = attrString
        
        let textHeight = attrString.height(withConstrainedWidth: ScreenWidth - 27*2)
        
        self.headerExtensionHeight = textHeight + 54 + 52
        
    }
    
    
    func test_set_up_view_data_set(){
        
        var text = sign
        
        if text.isEmpty{
            text = "星光月夜皆归你，我也归你"
        }
        
        let attrString = NSMutableAttributedString(string: text)
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.19, alpha: 1)]
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        self.signAttri = attrString
        
        let textHeight = attrString.height(withConstrainedWidth: ScreenWidth - 27*2)
        
        self.headerExtensionHeight = textHeight + 79 + 76
        
    }
    
    
    
}
